package net.funtip.ormgenerator.model;

import java.util.ArrayList;
import java.util.List;

public class Finder {

	public enum FinderType {single, many}
	
	private Entity entity;
	private String name;
	private List<FinderOperation> finderOperations;
	private List<OrderBy> orderBys;
	private FinderType type;
	private boolean limited;

	public Finder(Entity entity, String name) {
		this.entity = entity;
		this.name = name;
		this.finderOperations = new ArrayList<FinderOperation>();
		this.orderBys = new ArrayList<OrderBy>();
		this.type = FinderType.single;
		entity.addFinder(this);
	}
	
	public List<FinderOperation> getFinderOperations() {
		return finderOperations;
	}

	public void addFinderOperation(FinderOperation fo) {
		this.finderOperations.add(fo);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Entity getEntity() {
		return entity;
	}

	public List<OrderBy> getOrderBys() {
		return orderBys;
	}

	public void addOrderBy(OrderBy o) {
		this.orderBys.add(o);
	}

	public boolean isOrdered() {
		return orderBys.size() > 0;
	}
	
	public FinderType getType() {
		return type;
	}

	public void setType(FinderType type) {
		this.type = type;
	}

	public boolean isTypeMany() {
		return this.type.equals(FinderType.many);
	}

	public boolean isLimited() {
		return limited;
	}

	public void setLimited(boolean limited) {
		this.limited = limited;
	}

	public boolean isEmptyFinderOperationList() {
		return this.finderOperations.isEmpty();
	}
}
